package com.atguigu.gmall.product.exception.handler;


import com.atguigu.gmall.common.result.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.context.request.RequestContextHolder;

@ControllerAdvice  //所有controller的错误aop类
public class ProductAllExceptionHandler {


    @ResponseBody
    @ExceptionHandler(Exception.class)
    public Result handleArithException(Exception e){
        Result<Object> fail = Result.fail();

        //getMessage()：返回有关异常的详细信息
        fail.setMessage(e.getMessage());
        return fail;
    }



}
